package com.xju.dao.impl;

import java.util.List;

import com.xju.dao.UsersDao;
import com.xju.tools.DBTools;
import com.xju.tools.PageData;
import com.xjy.entity.Users;

public class UsersDaoImpl implements UsersDao {

	@Override
	public PageData<Users> getByPage(int page, int pageSize, String keywords) {

		String sql = "select * from tbl_user where username like ?";
		PageData<Users> pd = DBTools.exQueryByPage(sql, Users.class, page, pageSize, "%" + keywords + "%");
		return pd;
	}

	@Override
	public int add(Users user) {
		// TODO Auto-generated method stub
		String sql = "INSERT INTO `tbl_user` (`username`, `password`, `phone`, `email`, `gender`, `status`, `deleted`, `created_time`, `modified_time`) VALUES (?, ?, ?, ?, ?, ?, 0, now(), now())";
		int result = DBTools.exUpdate(sql, user.getUsername(), user.getPassword(), user.getPhone(), user.getEmail(),
				user.getGender(), user.getStatus());
		return result;
	}

	@Override
	public Users getUsers(String username, String password) {
		// TODO Auto-generated method stub
		String sql = "select * from tbl_user where username = ? and password = ? and status=1 and deleted=0";
		List<Users> list = (List<Users>) DBTools.exQuery(sql, Users.class, username, password);
		if (list.size() == 0) {
			return null;
		}
		return list.get(0);
	}
}
